package com.bruce.broadcastReceiver;

import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.telephony.TelephonyManager;

import com.bruce.phoneFlash.MyService;

public class MyReceiver extends BroadcastReceiver {
    public MyReceiver() {
    }

    @Override
    public void onReceive(Context context, Intent intent) {
        TelephonyManager tm= (TelephonyManager) context.getSystemService(Service.TELEPHONY_SERVICE);
        Intent intent1=new Intent(context,MyService.class);
        switch (tm.getCallState()){
            case TelephonyManager.CALL_STATE_RINGING://响铃
                context.startService(intent1);
                break;
            case TelephonyManager.CALL_STATE_OFFHOOK://接听
                context.stopService(intent1);
                break;
            case TelephonyManager.CALL_STATE_IDLE://挂断
                context.stopService(intent1);
                break;
        }
    }
}
